/**
 * This is a generated class and is not intended for modification.  To customize behavior
 * of this value object you may modify the generated sub-class of this class - VOPrice.as.
 */

package com.model.valueObjects
{
import com.adobe.fiber.services.IFiberManagingService;
import com.adobe.fiber.util.FiberUtils;
import com.adobe.fiber.valueobjects.IValueObject;
import com.model.valueObjects.VOPrice;
import flash.events.Event;
import flash.events.EventDispatcher;
import mx.binding.utils.ChangeWatcher;
import mx.collections.ArrayCollection;
import mx.events.CollectionEvent;
import mx.events.PropertyChangeEvent;
import mx.validators.ValidationResult;

import flash.net.registerClassAlias;
import flash.net.getClassByAlias;
import com.adobe.fiber.core.model_internal;
import com.adobe.fiber.valueobjects.IPropertyIterator;
import com.adobe.fiber.valueobjects.AvailablePropertyIterator;

use namespace model_internal;

[ExcludeClass]
public class _Super_VOPrice extends flash.events.EventDispatcher implements com.adobe.fiber.valueobjects.IValueObject
{
    model_internal static function initRemoteClassAliasSingle(cz:Class) : void
    {
        try
        {
            if (flash.net.getClassByAlias("VOPrice") == null)
            {
                flash.net.registerClassAlias("VOPrice", cz);
            }
        }
        catch (e:Error)
        {
            flash.net.registerClassAlias("VOPrice", cz);
        }
    }

    model_internal static function initRemoteClassAliasAllRelated() : void
    {
        com.model.valueObjects.VOPrice.initRemoteClassAliasSingleChild();
    }

    model_internal var _dminternal_model : _VOPriceEntityMetadata;

    /**
     * properties
     */
    private var _internal_VOPrice : ArrayCollection;
    model_internal var _internal_VOPrice_leaf:com.model.valueObjects.VOPrice;
    private var _internal_hilight : String;
    private var _internal_sgd_price : Number;
    private var _internal_other_price : Number;

    private static var emptyArray:Array = new Array();

    // Change this value according to your application's floating-point precision
    private static var epsilon:Number = 0.0001;

    /**
     * derived property cache initialization
     */
    model_internal var _cacheInitialized_isValid:Boolean = false;

    model_internal var _changeWatcherArray:Array = new Array();

    public function _Super_VOPrice()
    {
        _model = new _VOPriceEntityMetadata(this);

        // Bind to own data properties for cache invalidation triggering
        model_internal::_changeWatcherArray.push(mx.binding.utils.ChangeWatcher.watch(this, "VOPrice", model_internal::setterListenerVOPrice));
        model_internal::_changeWatcherArray.push(mx.binding.utils.ChangeWatcher.watch(this, "hilight", model_internal::setterListenerHilight));

    }

    /**
     * data property getters
     */

    [Bindable(event="propertyChange")]
    public function get VOPrice() : ArrayCollection
    {
        return _internal_VOPrice;
    }

    [Bindable(event="propertyChange")]
    public function get hilight() : String
    {
        return _internal_hilight;
    }

    [Bindable(event="propertyChange")]
    public function get sgd_price() : Number
    {
        return _internal_sgd_price;
    }

    [Bindable(event="propertyChange")]
    public function get other_price() : Number
    {
        return _internal_other_price;
    }

    /**
     * data property setters
     */

    public function set VOPrice(value:*) : void
    {
        var oldValue:ArrayCollection = _internal_VOPrice;
        if (oldValue !== value)
        {
            if (value is ArrayCollection)
            {
                _internal_VOPrice = value;
            }
            else if (value is Array)
            {
                _internal_VOPrice = new ArrayCollection(value);
            }
            else
            {
                throw new Error("value of VOPrice must be a collection");
            }
            this.dispatchEvent(mx.events.PropertyChangeEvent.createUpdateEvent(this, "VOPrice", oldValue, _internal_VOPrice));
        }
    }

    public function set hilight(value:String) : void
    {
        var oldValue:String = _internal_hilight;
        if (oldValue !== value)
        {
            _internal_hilight = value;
            this.dispatchEvent(mx.events.PropertyChangeEvent.createUpdateEvent(this, "hilight", oldValue, _internal_hilight));
        }
    }

    public function set sgd_price(value:Number) : void
    {
        var oldValue:Number = _internal_sgd_price;
        if (isNaN(_internal_sgd_price) == true || Math.abs(oldValue - value) > epsilon)
        {
            _internal_sgd_price = value;
            this.dispatchEvent(mx.events.PropertyChangeEvent.createUpdateEvent(this, "sgd_price", oldValue, _internal_sgd_price));
        }
    }

    public function set other_price(value:Number) : void
    {
        var oldValue:Number = _internal_other_price;
        if (isNaN(_internal_other_price) == true || Math.abs(oldValue - value) > epsilon)
        {
            _internal_other_price = value;
            this.dispatchEvent(mx.events.PropertyChangeEvent.createUpdateEvent(this, "other_price", oldValue, _internal_other_price));
        }
    }

    /**
     * Data property setter listeners
     *
     * Each data property whose value affects other properties or the validity of the entity
     * needs to invalidate all previously calculated artifacts. These include:
     *  - any derived properties or constraints that reference the given data property.
     *  - any availability guards (variant expressions) that reference the given data property.
     *  - any style validations, message tokens or guards that reference the given data property.
     *  - the validity of the property (and the containing entity) if the given data property has a length restriction.
     *  - the validity of the property (and the containing entity) if the given data property is required.
     */

    model_internal function setterListenerVOPrice(value:flash.events.Event):void
    {
        if (value is mx.events.PropertyChangeEvent)
        {
            if (mx.events.PropertyChangeEvent(value).newValue)
            {
                mx.events.PropertyChangeEvent(value).newValue.addEventListener(mx.events.CollectionEvent.COLLECTION_CHANGE, model_internal::setterListenerVOPrice);
            }
        }
        _model.invalidateDependentOnVOPrice();
    }

    model_internal function setterListenerHilight(value:flash.events.Event):void
    {
        _model.invalidateDependentOnHilight();
    }


    /**
     * valid related derived properties
     */
    model_internal var _isValid : Boolean;
    model_internal var _invalidConstraints:Array = new Array();
    model_internal var _validationFailureMessages:Array = new Array();

    /**
     * derived property calculators
     */

    /**
     * isValid calculator
     */
    model_internal function calculateIsValid():Boolean
    {
        var violatedConsts:Array = new Array();
        var validationFailureMessages:Array = new Array();

        var propertyValidity:Boolean = true;
        if (!_model.VOPriceIsValid)
        {
            propertyValidity = false;
            com.adobe.fiber.util.FiberUtils.arrayAdd(validationFailureMessages, _model.model_internal::_VOPriceValidationFailureMessages);
        }
        if (!_model.hilightIsValid)
        {
            propertyValidity = false;
            com.adobe.fiber.util.FiberUtils.arrayAdd(validationFailureMessages, _model.model_internal::_hilightValidationFailureMessages);
        }

        model_internal::_cacheInitialized_isValid = true;
        model_internal::invalidConstraints_der = violatedConsts;
        model_internal::validationFailureMessages_der = validationFailureMessages;
        return violatedConsts.length == 0 && propertyValidity;
    }

    /**
     * derived property setters
     */

    model_internal function set isValid_der(value:Boolean) : void
    {
        var oldValue:Boolean = model_internal::_isValid;
        if (oldValue !== value)
        {
            model_internal::_isValid = value;
            _model.model_internal::fireChangeEvent("isValid", oldValue, model_internal::_isValid);
        }
    }

    /**
     * derived property getters
     */

    [Transient]
    [Bindable(event="propertyChange")]
    public function get _model() : _VOPriceEntityMetadata
    {
        return model_internal::_dminternal_model;
    }

    public function set _model(value : _VOPriceEntityMetadata) : void
    {
        var oldValue : _VOPriceEntityMetadata = model_internal::_dminternal_model;
        if (oldValue !== value)
        {
            model_internal::_dminternal_model = value;
            this.dispatchEvent(mx.events.PropertyChangeEvent.createUpdateEvent(this, "_model", oldValue, model_internal::_dminternal_model));
        }
    }

    /**
     * methods
     */


    /**
     *  services
     */
    private var _managingService:com.adobe.fiber.services.IFiberManagingService;

    public function set managingService(managingService:com.adobe.fiber.services.IFiberManagingService):void
    {
        _managingService = managingService;
    }

    model_internal function set invalidConstraints_der(value:Array) : void
    {
        var oldValue:Array = model_internal::_invalidConstraints;
        // avoid firing the event when old and new value are different empty arrays
        if (oldValue !== value && (oldValue.length > 0 || value.length > 0))
        {
            model_internal::_invalidConstraints = value;
            _model.model_internal::fireChangeEvent("invalidConstraints", oldValue, model_internal::_invalidConstraints);
        }
    }

    model_internal function set validationFailureMessages_der(value:Array) : void
    {
        var oldValue:Array = model_internal::_validationFailureMessages;
        // avoid firing the event when old and new value are different empty arrays
        if (oldValue !== value && (oldValue.length > 0 || value.length > 0))
        {
            model_internal::_validationFailureMessages = value;
            _model.model_internal::fireChangeEvent("validationFailureMessages", oldValue, model_internal::_validationFailureMessages);
        }
    }

    model_internal var _doValidationCacheOfVOPrice : Array = null;
    model_internal var _doValidationLastValOfVOPrice : ArrayCollection;

    model_internal function _doValidationForVOPrice(valueIn:Object):Array
    {
        var value : ArrayCollection = valueIn as ArrayCollection;

        if (model_internal::_doValidationCacheOfVOPrice != null && model_internal::_doValidationLastValOfVOPrice == value)
           return model_internal::_doValidationCacheOfVOPrice ;

        _model.model_internal::_VOPriceIsValidCacheInitialized = true;
        var validationFailures:Array = new Array();
        var errorMessage:String;
        var failure:Boolean;

        var valRes:ValidationResult;
        if (_model.isVOPriceAvailable && _internal_VOPrice == null)
        {
            validationFailures.push(new ValidationResult(true, "", "", "VOPrice is required"));
        }

        model_internal::_doValidationCacheOfVOPrice = validationFailures;
        model_internal::_doValidationLastValOfVOPrice = value;

        return validationFailures;
    }
    
    model_internal var _doValidationCacheOfHilight : Array = null;
    model_internal var _doValidationLastValOfHilight : String;

    model_internal function _doValidationForHilight(valueIn:Object):Array
    {
        var value : String = valueIn as String;

        if (model_internal::_doValidationCacheOfHilight != null && model_internal::_doValidationLastValOfHilight == value)
           return model_internal::_doValidationCacheOfHilight ;

        _model.model_internal::_hilightIsValidCacheInitialized = true;
        var validationFailures:Array = new Array();
        var errorMessage:String;
        var failure:Boolean;

        var valRes:ValidationResult;
        if (_model.isHilightAvailable && _internal_hilight == null)
        {
            validationFailures.push(new ValidationResult(true, "", "", "hilight is required"));
        }

        model_internal::_doValidationCacheOfHilight = validationFailures;
        model_internal::_doValidationLastValOfHilight = value;

        return validationFailures;
    }
    

}

}
